package com.serkol.ams.bean;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.serkol.ams.entity.LoginLog;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class MyPage<T> extends Result {

    private long total;


    private long current;

    private long size;
    private long pages;
    private List<T> data;

    public static <M> MyPage<M> parsePage(IPage<M> page) {
        MyPage<M> myPage = new MyPage<>();
        myPage.setCurrent(page.getCurrent());
        myPage.setSize(page.getSize());
        myPage.setTotal(page.getTotal());
        myPage.setPages(page.getPages());
        myPage.setData(page.getRecords());
        myPage.setStatus(200);
        myPage.setSuccess(true);
        return myPage;
    }

    public static <T> MyPage<T> emptyPage() {
        MyPage<T> myPage = new MyPage<>();
        myPage.setCurrent(0);
        myPage.setSize(0);
        myPage.setTotal(0);
        myPage.setPages(0);
        myPage.setData(0);
        myPage.setStatus(204);
        myPage.setSuccess(false);
        return myPage;
    }
}